function ListNode(val) {
    this.val = val;
    this.next = null;
};
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var mergeTwoLists = function(l1, l2) {
    let p = l1;
    let q = l2;
    let newHead = new ListNode(-1);
    let temp = newHead;
    while (p != null && q != null ) {
        if (p.val <= q.val) {
            temp.next = new ListNode(p.val)
            p = p.next
        }else {
            temp.next = new ListNode(q.val)
            q = q.next
        }
        temp = temp.next
    }
    if (p == null) {
        temp.next = q
    }else {
        temp.next = p
    }
    return newHead.next
};
let l1 = new ListNode(1)
l1.next = new ListNode(2)
l1.next.next = new  ListNode(4)
let l2 =new  ListNode(1)
l2.next = new ListNode(3)
l2.next.next = new ListNode(4)
console.log(mergeTwoLists(l1,l2))
